package com.feiyu.buyer.controller;

import com.feiyu.buyer.dto.selectBuyerDto;
import com.feiyu.buyer.dto.updateBuyerDto;
import com.feiyu.buyer.entity.BuyerEntity;
import com.feiyu.buyer.service.BuyerService;
import com.feiyu.common.utils.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Doate
 * @Date: Created in 2021/4/16 3:30
 * @Description:
 */

@RestController
public class BuyerController {

    @Resource
    BuyerService buyerService;

    @PostMapping("/info")
    public R getMyInfo(@RequestHeader("userId") int userId) {

        return R.ok().put("data",buyerService.getInfo(userId));
    }

    @PostMapping("/update")
    public R updateInfo(@RequestHeader("userId") int userId, @RequestBody updateBuyerDto dto) {

        dto.setUserId(userId);
        return R.ok().put("data",buyerService.updateInfo(dto));
    }

    @PostMapping("/searchByParam")
    public R searchByParam(@RequestBody selectBuyerDto dto) {
        return R.ok().put("data",buyerService.searchByParam(dto));
    }

    @PostMapping("/searchById")
    public R searchById(@RequestBody selectBuyerDto dto) {
        return R.ok().put("data",buyerService.searchById(dto.getBuyerId()));
    }

}
